<template>
	<view class="charts-box">
		<qiun-data-charts type="line" :opts="opts" :chartData="echart1" :tooltipShow="false" :ontouch="true" />
		<qiun-data-charts type="line" :opts="opts" :chartData="echart2" :tooltipShow="false" :ontouch="true" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				opts: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 10, 0, 15],
					enableScroll: true,
					legend: {},
					xAxis: {
						disableGrid: true,
						scrollShow: true,
						itemCount: 4
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2
					},
					extra: {
						line: {
							type: "straight",
							width: 2,
							activeType: "hollow"
						}
					}
				},
				echart1: {},
				echart2: {}
			};
		},
		onLoad(e) {
			this.id = e.id
			uni.setNavigationBarTitle({
				title: e.name
			})
		},
		onReady() {
			this.getEchart1()
			this.getEchart2()
		},
		methods: {
			getEchart1() {
				this.$api.get('api/mobile/getWeekList', {
					id: this.id
				}).then(res => {
					const result = res.result
					let categories = []
					let data = []
					result.forEach(item => {
						categories.push(item.title)
						data.push(item.total)
					})
					this.echart1 = {
						categories: categories,
						series: [{
							name: "最近7天的用电量",
							data: data
						}]
					};
				})
			},
			getEchart2() {
				this.$api.get('api/mobile/getHourList', {
					id: this.id
				}).then(res => {
					const result = res.result
					let categories = []
					let data = []
					result.forEach(item => {
						categories.push(item.title)
						data.push(item.total)
					})
					this.echart2 = {
						categories: categories,
						series: [{
							name: "最近24小时的用电量",
							data: data
						}]
					};
				})
			},
		}
	};
</script>

<style scoped>
	/* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
	.charts-box {
		width: 100%;
		height: 300px;
	}
</style>